﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CmpClass; //添加的操作类

namespace CmpEdu
{
    public partial class FormTest4_2 : Form
    {
        public FormTest4_2()
        {
            InitializeComponent();
        }

        private void FormTest4_2_Load(object sender, EventArgs e)
        {
            this.Text = "重载技术的展示";
            labelResult.Text = "计算结果...";
        }

        /// <summary>
        /// 计算周长、面积和体积
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnCalc_Click(object sender, EventArgs e)
        {
            Round rd = new Round(); //命名空间CmpClass下的Round类
            if(tbRadius.Text!="")
            {                
                if (CorAorV.Text=="周长")
                {
                    labelResult.Text = "圆周长为： ";
                    float R = float.Parse(tbRadius.Text); //获取半径
                    float Cir = rd.Account(R);
                    labelResult.Text = "圆周长为： " + Cir.ToString();
                }                
                else if (CorAorV.Text=="面积")
                {
                    labelResult.Text = "圆面积为： ";
                    double R = double.Parse(tbRadius.Text); //获取半径
                    double Area = rd.Account(R);
                    labelResult.Text = "圆面积为： " + Area.ToString();
                }
                else if (CorAorV.Text=="体积")
                {
                    labelResult.Text = "圆柱体积为： ";
                    if (tbHeight.Text=="")
                    {
                        MessageBox.Show("必须输入高度！", "高度缺失", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        double R = double.Parse(tbRadius.Text); //获取半径
                        double H = double.Parse(tbHeight.Text); //获取高度
                        double Vol = rd.Account(R, H);
                        labelResult.Text = "圆柱体积为： " + Vol.ToString();
                    }
                }
                else if(CorAorV.Text=="")
                {
                    MessageBox.Show("请选择计算的类型！", "计算类别", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show("必须输入半径！", "半径缺失", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
    }
}
